from celery import Celery
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "luffeiapi.settings.dev")
import django
django.setup()

backend = 'redis://127.0.0.1:6379/1'  # 结果存储

broker = 'redis://127.0.0.1:6379/2'  # 消息中间件
app = Celery('main', backend=backend, broker=broker,
             include=['celery_task.goods_task', 'celery_task.order_task', 'celery_task.user_task', 'celery_task.home_task'])


# 时区
app.conf.timezone = 'Asia/Shanghai'
# 是否使用UTC
app.conf.enable_utc = False

# 任务的定时配置
from datetime import timedelta
from celery.schedules import crontab
app.conf.beat_schedule = {
    # 'send_sms': {
    #     'task': 'celery_task.user_task.send_sms',
    #     'schedule': timedelta(seconds=3),
    #     # 'schedule': crontab(hour=8, day_of_week=1),  # 每周一早八点
    #     'args': ('1895367221', '8888'),
    # },
    'update_banner': {
        'task': 'celery_task.home_task.update_banner',
        'schedule': timedelta(seconds=50),
        # 'schedule': crontab(hour=8, day_of_week=1),  # 每周一早八点
        'args': (),
    },

}